import random

def genkey(l=10,x='0123456789abcdefghijklmnopqrstuvwxyz'):
    return ''.join([random.choice(x) for i in range(l)])

#convert a list full of sets to a dict
# e.g:  [('id','someid'),('name','somename')]   =>  {'id':'someid', 'name':'somename'}
def setlist2dict(l):
    d = dict()
    for s in l:
        d[s[0]] = s[1]
    return d

def getValue(dom, tag):
    return dom.getElementsByTagName(tag)[0].firstChild.data

def getStandard(value, ruler):
    return abs(value * 100.0 / ruler)

def getEllipse(value):
    return (value[0]-2, value[1]-2, value[0]+2, value[1]+2)